<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加优惠券</title>
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <script src="../../layui/layui.js"></script>
    <script>
        layui.use('element', function() {
            var $ = layui.jquery;  //加载jQuery模块
            var element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        });
    </script>
</head>
<body>

 <form class="layui-form">
     <div class="layui-form-item">
         <input type="hidden" name="id"  class="layui-input" >
         <input type="hidden" name="inUsed"  class="layui-input" >
         <input type="hidden" name="image" class="image" class="layui-input" >
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">服装品牌</label>
         <div class="layui-input-inline">
             <input type="text" name="brand" placeholder="" required lay-verify="required" class="layui-input" >
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">服装编号</label>
         <div class="layui-input-inline">
             <input type="text" name="code" placeholder="" required lay-verify="required" class="layui-input" >
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">服装品类</label>
         <div class="layui-input-inline">
             <select name="type"  lay-verify="" lay-search>
                 <option value="">请选择</option>
                 <optgroup label="男士服装">
                     <option value="男士羽绒服">男士羽绒服</option>
                     <option value="男士棉衣">男士棉衣</option>
                     <option value="男士夹克">男士夹克</option>
                     <option value="男士牛仔裤">男士牛仔裤</option>
                     <option value="男士休闲裤">男士休闲裤</option>
                     <option value="男士针织衫">男士针织衫</option>
                     <option value="男士衬衫">男士衬衫</option>
                     <option value="男士卫衣">男士卫衣</option>
                     <option value="男士风衣">男士风衣</option>
                     <option value="男士POLO衫">男士POLO衫</option>
                     <option value="男士马甲">男士马甲</option>
                     <option value="男士休闲裤">男士休闲裤</option>
                     <option value="男士短裤">男士短裤</option>
                     <option value="男士西裤">男士西裤</option>
                     <option value="男士工装裤">男士工装裤</option>
                     <option value="男士运动裤">男士运动裤</option>
                     <option value="男士九分裤">男士九分裤</option>
                     <option value="男士卫裤">男士卫裤</option>
                 </optgroup>
                 <optgroup label="女士服装">
                     <option value="女士衬衫">女士衬衫</option>
                     <option value="衬衫">女士T恤打底</option>
                     <option value="女士毛衣针织">女士毛衣针织</option>
                     <option value="女士毛呢大衣">女士毛呢大衣</option>
                     <option value="女士西装外套">女士西装外套</option>
                     <option value="女士棉服外套">女士棉服外套</option>
                     <option value="女士牛仔长裤">女士牛仔长裤</option>
                     <option value="女士阔腿长裤">女士阔腿长裤</option>
                     <option value="女士休闲长裤">女士休闲长裤</option>
                     <option value="女士打底长裤">女士打底长裤</option>
                     <option value="女士半身裙秋">女士半身裙秋</option>
                     <option value="女士针织半裙">女士针织半裙</option>
                 </optgroup>
             </select>
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">X码数量</label>
         <div class="layui-input-inline">
             <input type="number" name="countsX" placeholder="" required lay-verify="required" class="layui-input" >
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">M码数量</label>
         <div class="layui-input-inline">
             <input type="number" name="countsM" placeholder="" required lay-verify="required" class="layui-input" >
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">L码数量</label>
         <div class="layui-input-inline">
             <input type="number" name="countsL" placeholder="" required lay-verify="required" class="layui-input" >
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">价格（元）</label>
         <div class="layui-input-inline">
             <input type="text" name="price" placeholder="" required lay-verify="required" class="layui-input" >
         </div>
     </div>
     <div class="layui-form-item">
         <label class="layui-form-label">服装介绍</label>
         <div class="layui-input-inline">
             <textarea name="desc" class="layui-textarea"></textarea>
         </div>
     </div>

     <div class="layui-form-item">
         <div class="layui-upload">
             <button type="button" class="layui-btn" id="test1">上传图片</button>
             <div class="layui-upload-list">
                 <div id="layer-photos-demo" class="layer-photos-demo">
                     <img src="" layer-src="" name="sokImg" class="layui-upload-img" id="demo1" style="width: 200px;height: 150px" title="查看大图">
                     <p id="demoText"></p>
                 </div>
             </div>
         </div>
     </div>

     <div class="layui-form-item">
         <div class="layui-input-block">
             <button id="loginBtn" class="layui-btn" lay-submit lay-filter="add">确定修改</button>
         </div>
     </div>
 </form>


 <script>
     layui.use(['upload', 'element', 'layer','form','laydate'], function() {
         var $ = layui.jquery
             , upload = layui.upload
             , element = layui.element
             , layer = layui.layer
             , form = layui.form
             ,laydate = layui.laydate;





         //普通图片上传
         var uploadInst = upload.render({
             elem: '#test1'
             ,url: '/uploadImage' //改成您自己的上传接口
             ,field:"image"
             ,before: function(obj){
                 //预读本地文件示例，不支持ie8
                 obj.preview(function(index, file, result){
                     $('#demo1').attr('src', result); //图片链接（base64）
                     $('#demo1').attr('layer-src', result); //图片链接（base64）
                 });
             }
             ,done: function(res){
                 //如果上传失败
                 if(res.code > 0){
                     return layer.msg('上传失败');
                 }
                 //上传成功
                 //$(".layui-form").append("<input  class='image' type='hidden' name='image' value='"+res.data+"'>");
                 $(".image").val(res.data)
             }
         });



         // 表单提交(异步)
         form.on('submit(add)', function(data){

             //获取隐藏域中的图片
             data.field.img=$(".image")[0].value;
             console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

             $.ajax({
                 url:"/stock/update"
                 ,method:"post"
                 ,data:data.field
                 ,type:'post'
                 ,success:function(res){
                     console.log(res)
                     if(res.code == 0){

                         layer.msg(res.msg,{icon:1,time:1000},function(){
                             parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                             window.parent.location.reload()
                         });

                     }else{
                         layer.msg(res.msg)
                     }
                 }
             })
             return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
         });
     })

     layer.photos({
         photos: '#layer-photos-demo'
         ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
     });
 </script>

</body>
</html>